#!/bin/sh

if [ -e games.sqlite ]; then
    db2pgn -o -s "Event,CAST(Round AS INTEGER),CAST(Board AS INTEGER)" games.sqlite normgames.pgn
    if [ "$?" != "0" ]; then
        return 1
    fi
else
    echo File: games.sqlite does not exist - too early to run this script
    return 0
fi

if [ "$1" = "-d" ]; then
    rm games.sqlite
    rm *test*.txt
    rm lista?.txt
fi
